﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Etong.Web;
/// <summary>
/// 用于与xml配置文件交互的实体类，对应数据库中的字段
/// </summary>
[Serializable]
public class ConfigColumns
{
	public ConfigColumns()
	{
        this.ListShowBoolLinkTrueText = "是";
        this.ListShowBoolLinkFalseText = "否";
        this.ListShowImgHeight = "40";
        this.EditShowImgHeight = "40";
        this.ListShowOrder = 1;
        this.EditShowOrder = 1;
        this.SearchShowOrder = 1;
        this.EditShowRangeMinValue = "0";
        this.EditShowRangeMaxValue = "9999999";
        this.SearchShowRangeMinValue = "0";
        this.SearchShowRangeMaxValue = "9999999";
        this.ListHAlign = HorizontalAlign.NotSet;
        this.SearchShowItemCountPerRow = 5;
	}

    public ConfigColumns(string columnName):this()
    {
        this.ColumnName = columnName;
        this.ListShowName = this.ColumnName;
        this.EditShowName = this.ColumnName;
        this.SearchShowName = this.ColumnName;
    }
    public ConfigColumns(string columnName, string typeStr)
        : this(columnName)
    {
        ColumnDataType = DataTypeFactory.GetColumnDataTyep(typeStr);
    }

    public ConfigColumns(string columnName, string typeStr, string inTable)
        : this(columnName, typeStr)
    {
        this.InTable = inTable;
    }

    public string InTable { get; set; }
    public string ColumnName { get; set; }
    public bool ListShowAllowSort { get; set; }
    public ColumnDataType ColumnDataType { get; set; }
    public bool IsAddShow { get; set; }
    public bool IsListShow { get; set; }
    public bool IsEditShow { get; set; }
    public bool IsSearchShow { get; set; }
    public string ListShowName { get; set; }
    public string EditShowName { get; set; }
    public string SearchShowName { get; set; }
    public ListShowType ListShowType { get; set; }
    public EditShowType EditShowType { get; set; }
    public SearchShowType SearchShowType { get; set; }
    public SearchRunType SearchShowRunType { get; set; }

    public int ListShowOrder { get; set; }
    public int EditShowOrder { get; set; }
    public int SearchShowOrder { get; set; }

    public string ListShowFormate { get; set; }
    public string ListShowImgWidth { get; set; }
    public string ListShowImgHeight { get; set; }
    public string ListShowLinkUrl { get; set; }
    public string ListShowLinkTarget { get; set; }
    public string ListShowLinkBoundDataField { get; set; }
    public string ListShowLinkText { get; set; }
    public string ListShowBoolLinkTrueText { get; set; }
    public string ListShowBoolLinkFalseText { get; set; }
    public string ListShowBoolLinkDateColumnName { get; set; }
    public string ListShowConfirmText { get; set; }
    public string ListShowForeignTable { get; set; }
    public string ListShowForeignTablePK { get; set; }
    public string ListShowForeignTableShowField { get; set; }
    public string ListShowTemplatePath { get; set; }
    public HorizontalAlign ListHAlign { get; set; }

    public string AddShowDefaultValue { get; set; }
    public string EditShowTextBoxWidth { get; set; }
    public string EditShowHiddenFrom { get; set; }
    public string EditShowAllowUploadExt { get; set; }
    public string EditShowImgWidth { get; set; }
    public string EditShowImgHeight { get; set; }
    public bool EditShowRequired { get; set; }
    public bool EditShowRange { get; set; }
    public ValidationDataType EditShowRangeType { get; set; }
    public string EditShowRangeMinValue { get; set; }
    public string EditShowRangeMaxValue { get; set; }
    public bool EditShowRegExp { get; set; }
    public string EditShowRegExpText { get; set; }
    public string EditShowRegExpErrMessage { get; set; }
    public string EditShowSqlText { get; set; }
    public string EditShowBindValueField { get; set; }
    public string EditShowBindTextField { get; set; }
    public string EditShowTemplatePath { get; set; }
    public string EditShowTemplateFields { get; set; }
    public string EditShowTemplateValuesFrom { get; set; }

    public string SearchShowSqlText { get; set; }
    public string SearchShowBindValueField { get; set; }
    public string SearchShowBindTextField { get; set; }
    public bool SearchShowRange { get; set; }
    public ValidationDataType SearchShowRangeType { get; set; }
    public string SearchShowRangeMinValue { get; set; }
    public string SearchShowRangeMaxValue { get; set; }
    public bool SearchShowRegExp { get; set; }
    public string SearchShowRegExpText { get; set; }
    public string SearchShowRegExpErrMessage { get; set; }
    public string SearchShowTemplatePath { get; set; }
    public string SearchShowTemplateFields { get; set; }
    public string SearchShowTemplateValuesFrom { get; set; }
    public string SearchShowRunSql { get; set; }
    public int SearchShowItemCountPerRow { get; set; }

    /// <summary>
    /// 根据传入的值，得到当前数据库应该使用的sql文本
    /// 如当类型是字符时，传入a得到'a'
    /// </summary>
    /// <param name="str">原始数据</param>
    /// <returns>得到的文本</returns>
    public string GetSqlValueString(string str)
    {
        return DataTypeFactory.GetSqlValue(str, this.ColumnDataType);
    }
}